package com.ss.android.article.browser.a;

import android.app.Application;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffXfermode;
import android.graphics.RectF;
import android.graphics.Typeface;
import android.net.Uri;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.annotation.WorkerThread;
import android.support.v4.content.ContextCompat;
import android.text.TextUtils;
import android.util.LruCache;

import com.ss.android.article.browser.R;
import com.ss.android.common.app.AbsApplication;

import java.io.File;

import inline.ResourcesDemo;

public class a {
    private static a a;
    @NonNull private final BitmapFactory.Options b;
    @NonNull private final Application c;
    @NonNull private final LruCache<String, Bitmap> d;
    private final int e;

    private a(@NonNull Application arg3) {

        this.b = new BitmapFactory.Options();
        com.ss.android.article.browser.c.d.a();
        this.d = new b();
        this.c = arg3;
        this.e = this.c.getResources().getDimensionPixelSize(R.dimen.c4);
    }

    static Application a(a arg1) {
        return arg1.c;
    }

    static Bitmap a(a arg1, String arg2) {
        return arg1.b(arg2);
    }

    public static a a() {
        if(a == null) {
            Class v1 = a.class;
            synchronized (v1){
                if(a == null) {
                    a = new a(AbsApplication.getApplication());
                }
            }
        }

        return a;
    }

    @NonNull @WorkerThread public static File a(@NonNull Application arg4, @NonNull Uri arg5) {
        if(arg5 != null && !TextUtils.isEmpty(arg5.getScheme()) && !TextUtils.isEmpty(arg5.getHost())) {
            return new File(arg4.getCacheDir(), arg5.getHost().hashCode() + ".png");
        }
        throw new RuntimeException("Unsafe uri provided");
    }

    static void a(a arg2, String arg3, Bitmap arg4) {
        LruCache v1 = arg2.d;
        synchronized (v1){
            arg2.d.put(arg3, arg4);
        }
    }

    @NonNull public final Bitmap a(@Nullable String arg11) {
        int v0_2;
        float v9 = 2f;
        char v0 = !TextUtils.isEmpty(((CharSequence)arg11)) ? arg11.charAt(0) : '?';
        Character v1 = Character.valueOf(v0);
        Application v0_1 = this.c;
        switch(Math.abs(Character.getNumericValue(v1.charValue()) % 4)) {
            case 0: {
                v0_2 = ContextCompat.getColor(((Context)v0_1), R.color.fl);
                break;
            }
            case 1: {
                v0_2 = ContextCompat.getColor(((Context)v0_1), R.color.fm);
                break;
            }
            case 2: {
                v0_2 = ContextCompat.getColor(((Context)v0_1), R.color.fo);
                break;
            }
            case 3: {
                v0_2 = ContextCompat.getColor(((Context)v0_1), R.color.fn);
                break;
            }
            default: {
                v0_2 = -16777216;
                break;
            }
        }

        Bitmap v2 = Bitmap.createBitmap(this.e, this.e, Bitmap.Config.ARGB_8888);
        Canvas v3 = new Canvas(v2);
        Paint v4 = new Paint();
        v4.setColor(v0_2);
        v4.setTypeface(Typeface.create(Typeface.SANS_SERIF, 1));
        v4.setTextSize(((float) ResourcesDemo.dp2px(14f)));
        v4.setAntiAlias(true);
        v4.setTextAlign(Paint.Align.CENTER);
        v4.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_OVER));
        v0_2 = ResourcesDemo.dp2px(v9);
        v3.drawRoundRect(new RectF(0f, 0f, ((float)v3.getWidth()), ((float)v3.getHeight())), ((float)v0_2), ((float)v0_2), v4);
        v0_2 = v3.getWidth() / 2;
        int v5 = ((int)((((float)(v3.getHeight() / 2))) - (v4.descent() + v4.ascent()) / v9));
        v4.setColor(-1);
        v3.drawText(v1.toString(), ((float)v0_2), ((float)v5), v4);
        return v2;
    }

    @NonNull public final com.a.a.a a(@NonNull Bitmap arg2, @NonNull String arg3) {
        return com.a.a.a.a(new com.ss.android.article.browser.a.d(this, arg3, arg2));
    }

    @Nullable private Bitmap b(@NonNull String arg3) {
        LruCache v1 = this.d;
        synchronized (v1){
            return this.d.get(arg3);
        }
    }

    static BitmapFactory.Options b(a arg1) {
        return arg1.b;
    }
}

